//
//  QBUser.swift
//  Wei91BoiOS
//
//  Created by bing on 16/3/25.
//  Copyright © 2016年 bing. All rights reserved.
//

import UIKit

class QBUser: NSObject {

    /// 用户UID
    var id: Int64 = 0
    
    /// 用户头像地址（中图），50×50像素
    var profile_image_url: String?
    
    /// 用户昵称
    var screen_name: String?
    
    /// 会员等级1-6，这个属性给别人用不方便，需要做判断
    var mbrank: Int = 0 {
        didSet {
            // 当KVC给mbrank赋值的时候,我们给mbrankImage赋值
            if mbrank > 0 && mbrank <= 6 {
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            } else {
                // 防止cell复用，没有会员的就不要等级
                mbrankImage = nil
            }
        }
    }
    
    /// mbrankImage,会员等级对应的图片
    var mbrankImage: UIImage?
    
    /// verified_type 没有认证:-1   认证用户:0  企业认证:2,3,5  达人:220
    var verified_type: Int = -1 {
        didSet {
            switch verified_type {
            case 0:
                verified_typeImage = UIImage(named: "avatar_vip")
            case 2,3,5:
                verified_typeImage = UIImage(named: "avatar_enterprise_vip")
            case 220:
                verified_typeImage = UIImage(named: "avatar_grassroot")
            default:
                verified_typeImage = nil
            }
        }
    }
    
    var verified_typeImage: UIImage?
    
    /// 字典转模型
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    override var description: String {
        // 只读计算型属性
        let keys = ["id", "profile_image_url", "screen_name", "mbrank", "verified_type"]
        
        return "\n\t:\(dictionaryWithValuesForKeys(keys).description)"
    }
}
